package com.scoy.honeymei.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;

import com.scoy.honeymei.wxapi.alipay.IAlPayResultListener;
import com.scoy.honeymei.wxapi.alipay.PayAsyncTask;

import org.greenrobot.eventbus.EventBus;


public class FastPay {

    //设置支付回调监听

    private Activity mActivity = null;

    private FastPay(Activity activity) {
        this.mActivity = activity;
    }


    public static FastPay create(Activity activity) {
        return new FastPay(activity);
    }

    /**
     * 开启异步任务，调起支付宝
     */
    public void aliPay(String paySign) {
        final PayAsyncTask payAsyncTask = new PayAsyncTask(mActivity, mIAlPayResultListener);
        payAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, paySign);
    }

    //支付宝支付结果回调
    private IAlPayResultListener mIAlPayResultListener = new IAlPayResultListener() {
        @Override
        public void onPaySuccess() {
            EventBus.getDefault().post(new PayEvent(0));
        }

        @Override
        public void onPaying() {

        }

        @Override
        public void onPayFail() {
            EventBus.getDefault().post(new PayEvent(-1));
        }

        @Override
        public void onPayCancel() {
            EventBus.getDefault().post(new PayEvent(-2));
        }

        @Override
        public void onPayConnectError() {

        }
    };


}
